package logic

import (
	"context"
	"house123/B/src/model/mysql"

	"house123/B/src/house"
	"house123/B/src/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *house.GoodsAddRequest) (*house.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	var goods = mysql.Goods{
		Title:  in.Title,
		Cover:  in.Cover,
		Price:  float64(in.Price),
		Stock:  in.Stock,
		Status: in.Status,
	}
	err := goods.Create()
	if err != nil {
		return nil, err
	}

	return &house.GoodsAddResponse{GoodsId: int64(goods.ID)}, nil
}
